<%-- 
    Document   : connectDatabase
    Created on : Apr 15, 2011, 2:56:40 PM
    Author     : NguyenThuan
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%
            Connection conn = null;
            String url = "jdbc:mysql://localhost:3306/";
            String dbName = "user_register";
            String driver = "com.mysql.jdbc.Driver";
            String username = "root";
            String password = "123456789";
            String sqlString = null;
            ResultSet rst = null;
            Statement stmt = null;
            try {
                Class.forName(driver).newInstance();
                conn = DriverManager.getConnection(url + dbName, username, password);
                stmt = conn.createStatement();
                out.println("Kết nối thành công");
            } catch (Exception ex) {
                out.println("Unenable to connect to database");
                out.println("\nError: " + ex.getMessage());
            }
            if (!conn.isClosed()) {
                sqlString = "select * from register";
                rst = stmt.executeQuery(sqlString);
%>
<table border="1px">
    <tr>
        <th>id</th>
        <th>username</th>
        <th>password</th>
        <th>firstname</th>
        <th>lastname</th>
        <th>email</th>
        <th>state</th>
        <th>city</th>
        <th>country</th>

    </tr>
    <%
                    int no = 1;
                    while (rst.next()) {
    %>
    <tr>
        <td><%=rst.getString("id")%></td>
        <td><%=rst.getString("username")%></td>
        <td><%=rst.getString("password")%></td>
        <td><%=rst.getString("firstname")%></td>
        <td><%=rst.getString("lastname")%></td>
        <td><%=rst.getString("email")%></td>
        <td><%=rst.getString("state")%></td>
        <td><%=rst.getString("city")%></td>
        <td><%=rst.getString("country")%></td>
    </tr>

    <%
                        no++;
                    }%>
</table>
<%
                rst.close();
                stmt.close();
                conn.close();
            }
%>
